package com.hqyj.cl.controller;

import com.github.pagehelper.PageInfo;
import com.hqyj.cl.pojo.User;
import com.hqyj.cl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @description：
 * @author：cc
 * @date：2021/10/12 13:51
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @RequestMapping("/login")
    @ResponseBody
    public Map<String,String> login(User user){
        return userService.login(user);
    }

    @RequestMapping("/userList")
    public String userList(User user, HttpServletRequest request){
        List<User> list = userService.findAll();
        request.setAttribute("list", list);
//        return "user-list";
        return "userlist";
    }

    @RequestMapping("/queryAll")
    @ResponseBody
    public PageInfo<User> queryAll(int pageNum, int pageSize){
        // 判断pageNum是否为-1，如果为-1，则表示第一次请求
        if(pageNum == -1)
            pageNum = 1;
       return userService.queryAll(pageNum, pageSize);
    }
}
